<template>
  <div>
    <el-breadcrumb separator-class='el-icon-arrow-right'>
      <el-breadcrumb-item to='/home'>首页</el-breadcrumb-item>
      <el-breadcrumb-item >订单管理</el-breadcrumb-item>
      <el-breadcrumb-item >订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span='8'>
          <el-input>
            <el-button slot='append' icon='el-icon-search' ></el-button>
          </el-input>
        </el-col>
        <el-button type='primary' style='margin-left: 20px'>添加订单</el-button>
      </el-row>
      <el-table :data='orderList' border stripe>
        <el-table-column type='index' label='#'></el-table-column>
        <el-table-column label='订单编号' prop='order_number'></el-table-column>
        <el-table-column label='订单价格' prop='order_price'></el-table-column>
        <el-table-column label='是否付款' prop='pay_status'>
          <template slot-scope='scope'>
            <el-tag v-if='scope.pay_status === 1' type='success'>已付款</el-tag>
            <el-tag v-else type='danger'>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label='是否发货' prop='is_send'>
          <template slot-scope='scope'>
            {{scope.row.is_send}}
          </template>
        </el-table-column>
        <el-table-column label='下单时间' prop='create_time'>
          <template slot-scope='scope'>
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label='操作'>
          <template>
            <el-button size='mini' type='primary' icon='el-icon-edit' @click='showAddrDialog'></el-button>
            <el-button size='mini' type='success' icon='el-icon-location' @click='showProgressDialog'></el-button>
          </template>
        </el-table-column>
      </el-table>
<!--      分页器-->
      <el-pagination
        @size-change='handleSizeChange'
        @current-change='handleCurrentChange'
        :current-page='queryInfo.pagenum'
        :page-sizes='[10, 15, 20, 25]'
        :page-size='queryInfo.pagesize'
        layout='total, sizes, prev, pager, next, jumper'
        :total='total'>
      </el-pagination>
    </el-card>
<!--    修改地址弹框-->
    <el-dialog title='修改地址' width='50%' @close='addrDialogClose' :visible.sync='addrDialogVisible' >
      <el-form :model='addrForm' ref='addrRef' :rules='addrRules' label-width='100px'>
        <el-form-item label='省市区/县' prop='address1'>
          <el-cascader :options='cityData' v-model='addrForm.address1'></el-cascader>
        </el-form-item>
        <el-form-item label='详细地址' prop='address2'>
          <el-input v-model='addrForm.address2'></el-input>
        </el-form-item>
      </el-form>
      <span slot='footer'>
        <el-button @click='addrDialogVisible = false'>取消</el-button>
        <el-button @click='commitAddr' type='primary'>确定</el-button>
      </span>
    </el-dialog>
<!--    物流信息对话框-->
    <el-dialog title='物流信息' :visible.sync='progressDialogVisible'>
      <el-timeline >
        <el-timeline-item
          v-for='(activity, index) in progressList'
          :key='index'
          :timestamp='activity.timestamp'>
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot='footer'>
        <span slot='footer'>
        <el-button @click='progressDialogVisible = false'>取消</el-button>
        <el-button @click='progressDialogVisible = false' type='primary'>确定</el-button>
      </span>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  name: 'Order',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      addrDialogVisible: false,
      total: 0,
      orderList: [],
      addrForm: {
        address1: [],
        address2: ''
      },
      cityData: cityData,
      addrRules: {
        address1: [
          { required: true, message: '请选择省市区', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      progressDialogVisible: false,
      progressList: [
        {
          time: '2018-05-10 09:39:00',
          ftime: '2018-05-10 09:39:00',
          context: '已签收,感谢使用顺丰,期待再次为您服务',
          location: ''
        },
        {
          time: '2018-05-10 08:23:00',
          ftime: '2018-05-10 08:23:00',
          context: '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
          location: ''
        }
      ]
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: result } = await this.$http.get('orders', { params: this.queryInfo })
      if (result.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.$message.success('获取订单列表成功')
      this.orderList = result.data.goods
      console.log(result)
      this.total = result.data.total
    },
    handleSizeChange (newsize) {
      this.queryInfo.pagesize = newsize
      this.getOrderList()
    },
    handleCurrentChange (newpage) {
      this.queryInfo.pagenum = newpage
      this.getOrderList()
    },
    showAddrDialog () {
      this.addrDialogVisible = true
    },
    commitAddr () {
      this.addrDialogVisible = false
    },
    addrDialogClose () {
      // 清楚表单内容
      this.$refs.addrRef.resetFields()
    },
    async showProgressDialog () {
      this.progressDialogVisible = true
    }
  },
  computed: {
  }
}
</script>

<style scoped>

</style>
